class AssemblyOrder < ActiveRecord::Base
  has_many :assembly_order_details ,:dependent => :destroy  #级联删除子表
  has_many :assembly_order_products ,:dependent => :destroy  #级联删除子表
  belongs_to :warehouse
  belongs_to :employee
  belongs_to :department
  belongs_to :company
  belongs_to :product
  belongs_to :auditor, :class_name => 'Employee', :foreign_key => 'auditor_id'

  scope :findAllAssemblyOrders, ->(conditionsStr,conditionsHash,paramsHash) { includes( [:employee,:department,:auditor,:warehouse,:product,:assembly_order_products]).where([conditionsStr,conditionsHash]).offset(paramsHash[:offset]).limit(paramsHash[:limit]).order('assembly_orders.updated_at DESC')}

  scope :countAllAssemblyOrders, ->(conditionsStr,conditionsHash) { includes( [:assembly_order_products]).where([conditionsStr,conditionsHash]).count()}
end
